react中使用构建缓存_如何在React中构建热图
react中使用构建缓存
Heat maps are a great way of visualizing correlations among two data sets. With colors and gradients, it is possible to see patterns in the data almost instantly.
热图是可视化两个数据集之间相关性的一种好方法。 使用颜色和渐变,可以几乎立即看到数据中的图案。
I went searching for a heat map implementation in npm, but was unable to find one that I liked, so I wrote my own. It is still a work in progress, but does provide basic functionality.
我在npm中搜索热图实现,但找不到我喜欢的实现,因此我编写了自己的 。 这项工作仍在进行中,但确实提供了基本功能。
There are actually two parts to the implementation: jsheatmap takes headings and row data to produce a JSON object where the raw input is scaled from 0.0 to 1.0 and then RGB colors are mapped to those scaled values. I will confess that most of this was already worked out by Andrew Noske, who provided a partial C++ implementation in his blog. Transliterating C++ to TypeScript was relatively easy.
实现实际上包括两部分: jsheatmap使用标题和行数据来生成JSON对象,其中原始输入从0.0缩放到1.0,然后将RGB颜色映射到这些缩放值。 我要承认,其中大多数已经由Andrew Noske解决了,他在他的博客中提供了部分C ++实现 。 将C ++音译为TypeScript相对容易。
The second part is an HTML presentation of the JSON data returned by jsheatmap. This would typically be the responsibility of the user of jsheatmap module, but I did build a general-purpose React application that demonstrates how HTML table cells can be used as a heat map representation.
第二部分是jsheatmap返回的JSON数据HTML表示。 这通常是jsheatmap模块用户的责任,但是我确实构建了一个通用的React应用程序 ,该应用程序演示了如何将HTML表单元格用作热图表示形式。
基础 (The basics)
First, install jsheatmap:
首先,安装jsheatmap:
npm i -S jsheatmap
npm i -S jsheatmap
As mentioned, jsheatmap was written in TypeScript, but npm will install the generated JavaScript version of the TypeScript program, which is what your application will use.
如前所述,jsheatmap是用TypeScript编写的,但是npm将安装TypeScript程序的生成JavaScript版本,这是您的应用程序将使用的版本。
Next, import the jsheatmap components.
接下来,导入jsheatmap组件。
import HeatMap, { Style } from "jsheatmap"
import HeatMap, { Style } from "jsheatmap"
The Style
component is not strictly required. As of this writing, there are only two Styles: SIMPLE and FANCY. FANCY is the default, which uses a 5-color gradient for the heat map RGB data. SIMPLE uses a three-color gradient, which you might prefer for smaller data sets. The style is passed to the getData()
method, as will be shown later.
Style
组件不是严格要求的。 在撰写本文时,只有两种样式:SIMPLE和FANCY。 FANCY是默认设置,它对热图RGB数据使用5色渐变。 SIMPLE使用三色渐变,对于较小的数据集,您可能更喜欢这种渐变。 样式将传递到getData()
方法,如稍后所示。
Instantiate a HeatMap with headings (column names) and row data:const heatMap = new HeatMap(headings, rows)
使用标题(列名)和行数据实例化const heatMap = new HeatMap(headings, rows)
: const heatMap = new HeatMap(headings, rows)
where headings is an array of strings (column headings) and rows is an array of labels and cell data. For example:
其中标题是字符串(列标题)的数组,行是标签和单元格数据的数组。 例如:
// Days of rain in summer summer months, by year
const headings = ["June", "July", "August", "September"] // the months
const rows = [["2015", [9, 5, 6, 8]], // the years and rainy days by month["2016", [7, 5, 10, 7]],["2017", [7, 4, 3, 9]],["2018", [10, 5, 6, 8]],["2019", [8, 9, 3, 1]],]
转换为RGB (Converting to RGB)
Now is time to get the heat map data:
现在是时候获取热图数据了:
// const data = heatMap.getData({ style: Style.SIMPLE });
const data = heatMap.getData();
The default style is FANCY (five color gradient) whereas SIMPLE would use a three-color gradient for the RGB mapping.
默认样式为FANCY(五种颜色渐变),而SIMPLE将为RGB映射使用三色渐变。
Cell values are then scaled, relative to each other, with scale values determined by the high and low values of the input. Once all the inputs have been scaled from 0.0 to 1.0, they can be mapped to RGB color values. All of this data is returned by getData():
然后,将单元格值相对于彼此进行缩放,缩放值由输入的高值和低值确定。 一旦所有输入都从0.0缩放到1.0,就可以将它们映射为RGB颜色值。 所有这些数据由getData()返回:
{"headings": ["Jun","Jul","Aug","Sep"],"high": 9,"low": 4,"rows": [{"label": "2015","cells": {"values": [7,5,6,8],"colors": [{"red": 0.6249999999999998,"green": 1,"blue": 0},{"red": 0,"green": 0.588235294117647,"blue": 1},{"red": 0,"green": 1,"blue": 0.625},{"red": 1,"green": 0.588235294117647,"blue": 0}],"scales": [0.6,0.2,0.4,0.8]}},{"label": "2016","cells": {"values": [7,5,5,7],"colors": [{"red": 0.6249999999999998,"green": 1,"blue": 0},{"red": 0,"green": 0.588235294117647,"blue": 1},{"red": 0,"green": 0.588235294117647,"blue": 1},{"red": 0.6249999999999998,"green": 1,"blue": 0}],"scales": [0.6,0.2,0.2,0.6]}},{"label": "2017","cells": {"values": [7,4,5,9],"colors": [{"red": 0.6249999999999998,"green": 1,"blue": 0},{"red": 0,"green": 0,"blue": 1},{"red": 0,"green": 0.588235294117647,"blue": 1},{"red": 1,"green": 0,"blue": 0}],"scales": [0.6,0,0.2,1]}},{"label": "2018","cells": {"values": [6,5,7,8],"colors": [{"red": 0,"green": 1,"blue": 0.625},{"red": 0,"green": 0.588235294117647,"blue": 1},{"red": 0.6249999999999998,"green": 1,"blue": 0},{"red": 1,"green": 0.588235294117647,"blue": 0}],"scales": [0.4,0.2,0.6,0.8]}},{"label": "2019","cells": {"values": [8,6,6,8],"colors": [{"red": 1,"green": 0.588235294117647,"blue": 0},{"red": 0,"green": 1,"blue": 0.625},{"red": 0,"green": 1,"blue": 0.625},{"red": 1,"green": 0.588235294117647,"blue": 0}],"scales": [0.8,0.4,0.4,0.8]}}]
}
For the demonstration application, I use React to generate a table with each <td> element's background styled as follows:
对于演示应用程序 ,我使用React生成一个表,每个表的背景样式如下:
const background = (rgb) => { return `rgb(${rgb.red * 100}%, ${rgb.green * 100}%, ${rgb.blue * 100}%)`;
}
Where rgb()
is the built-in CSS function for RGB colors, and the passed-in rgb
parameter comes from the cell colors of the row generated by getData()
. To run the implementation, first clone the repository:
其中rgb()
是RGB颜色的内置CSS函数,而传入的rgb
参数来自getData()
生成的行的单元格颜色。 要运行实现,请首先克隆存储库:
git clone https://github.com/JeffML/sternomap.git
git clone https://github.com/JeffML/sternomap.git
then go to the sternomap folder and run:
然后转到sternomap文件夹并运行:
npm install
npm install
finally:
最后:
npm run start
npm run start
As an aside: the application was originally generated using Create React App, and the README.md file explains all that in detail.
顺便说一句 :该应用程序最初是使用Create React App生成的, README.md文件详细解释了所有这些内容。
输出 (The output)
Once the script has finished, it will load a page in your browser (I use Chrome). Here's a snapshot:
脚本完成后,它将在浏览器中加载页面(我使用Chrome)。 这是快照:
This shows rainy days per month in each cell, by year. From this you can see that the driest months are July and August, with the wettest being September. The number inside each cell is the scaled value of the raw input (rainy days), so the least rainy days were in July of 2017, and the most in September of that year.
这显示了每个单元格每个月每月的雨天。 从中可以看到最干旱的月份是七月和八月,最潮湿的月份是九月。 每个单元格中的数字是原始输入的换算值(雨天),因此雨天最少的是2017年7月,雨天最多的是该年9月。
彩虹的颜色 (A rainbow of colors)
I can generate a data set where the value of each cell is the sum of it's x + y coordinates. For row labels, I use the npm module casual to create them.
我可以生成一个数据集,其中每个单元格的值是其x + y坐标的总和。 对于行标签,我使用npm模块Casual来创建它们。
总结 (The wrap up)
I have some plans to use this heat map implementation in other projects, which I am sure will require changes to the API, but the basics should remain the same. If you decide to try this and find it useful, let me know.
我有一些计划在其他项目中使用此热图实现,我敢肯定,这需要更改API,但基本知识应保持不变。 如果您决定尝试此方法并发现它有用,请告诉我。
翻译自: https://www.freecodecamp.org/news/a-heat-map-implementation-in-typescript/
react中使用构建缓存
相关文章:
oracle rman异机恢复
Oracle源主机Oracle目标主机主机平台CentOS6.2(final)CentOs6.2(FInal)主机名 vickrmanIP地址192.168.1.11192.168.1.10实例名字orclorclOracle版本号11.2.0.411。2.0.4Oracle数据文件存储filesystemfilesystem控制文件路径/u01/a…

高阶函数-lambda表达式
#2.6 map()# 第一个参数传入一个函数,,第二个参数为一个可迭代对象li_1 (1,3,5,7)def funcA(x): return x*xm1 map(funcA,li_1)print(type(m1))print(m1())# 2.6 reduce()# 第一个参数传入一个函数,第二个参数 可以迭代对象 ,…

CSS动画效果无限循环放大缩小
效果图: CSS动画效果无限循环放大缩小 <image class"anima" mode"widthFix" click"nav" src"/static/1_btn.png"></image>.anima {animation-name: likes; // 动画名称animation-direction: alternate; // 动…

solidity 编程练习_学习Solidity编程语言并开始为区块链开发
solidity 编程练习Learn to program in Solidity in this full tutorial from Dapp University. Solidity is an object-oriented programming language for writing smart contracts. It is used for implementing smart contracts on various blockchain platforms, most not…

性能测试之二——常用的性能测试策略
性能测试的常用策略有: 1、基准测试 单用户测试需要打开控制台,获取Analysis结果() 2、并发测试 多用户在同一时间做同一事情或执行同一操作,针对同一业务(LR精确到毫秒),一般测试并…

KBEngine服务器环境搭建
1.概要及环境 KBEngine是一款开源服务端引擎(中文官网http://kbengine.org/cn/),能够在Linux、Windows下部署,为了学习方便,我们在本机Windows下进行服务器环境的搭建。 1)服务端源代码 https://github.com…

小程序判断屏幕是长屏还是短屏手机,iPhone X 类型还是 iPhone 6类型
直接看代码 globalData: {udgeBigScreen: false,//判断屏幕 }, onLaunch: function(e) {/**判断屏幕大小 */var judgeBigScreen () > {let result false;const res wx.getSystemInfoSync();const rate res.windowHeight / res.windowWidth;let limit res.w…

桌面应用程序 azure_如何开始使用Microsoft Azure-功能应用程序,HTTP触发器和事件队列...
桌面应用程序 azure"Serverless" architecture is all the rage in tech land at the moment, including heavy usage at my new workplace. “无服务器”架构目前在科技界风靡一时,包括在我的新工作场所中大量使用。 Microsoft jumped into this space …

开始Flask项目
新建Flask项目。设置调试模式。理解Flask项目主程序。使用装饰器,设置路径与函数之间的关系。使用Flask中render_template,用不同的路径,返回首页、登录员、注册页。用视图函数反转得到URL,url_for(‘login’),完成导航…

JavaScript中的加法运算
<head runat"server"> <title>JavaScript实现加法计算器</title> <script type"text/javascript"> function Sum() { var txtbox1 document.getElementById("txtbox1"); var txtbox2 document.getElementById("…

计算机视觉技术 图像分类_如何训练图像分类器并教您的计算机日语
计算机视觉技术 图像分类介绍 (Introduction) Hi. Hello. こんにちは你好 你好。 こんにちは Those squiggly characters you just saw are from a language called Japanese. You’ve probably heard of it if you’ve ever watched Dragon Ball Z.您刚刚看到的那些蠕动的字符…

history对象
history对象记录了用户曾经浏览过的页面(URL),并可以实现浏览器前进与后退相似导航的功能。 注意:从窗口被打开的那一刻开始记录,每个浏览器窗口、每个标签页乃至每个框架,都有自己的history对象与特定的window对象关联。 语法: w…

无限循环动画实现
先来个效果图 示例代码是先缩小移动,然后无限循环左右晃动,希望能够帮助到你,点个赞吧~ 实现代码 <image class"element1" load"element1_load" :animation"animationData" src"../../static/element…

利用属性封装复杂的选项
1、考虑这样一个场景。 我们的程序中有一个“选项”窗口,这个窗口包含很多选项。其中有一个选项是单选类型的,用户可以从N个选项值中选择一个。 我们需要在用户单击“确定”按钮后把用户选择的值保存到文件中,程序下次启动时再读取到内存中。…

react 渲染道具_关于React道具的另一篇文章
react 渲染道具You could say this topic has been done to death, but lately I’ve started using a technique that I dont recall having come across elsewhere. While its not particularly clever, it is concise. So please forgive one more post on the topic...你…

高可用集群的概念
一:什么是高可用集群 高可用集群(High Availability Cluster,简称HA Cluster),是指以减少服务中断时间为目的得服务器集群技术。它通过保护用户得业务程序对外部间断提供的服务,把因为软件,硬件…

node.js 出现cannot find module ‘xxx‘ 解决办法
找不到模块的解决方案 : 把node_module整个文件夹删掉,然后npm clean cache,看下package.json里有没有express的依赖项,有的话直接npm install,没有的话 npm install express --save npm clean cache 如果不行的话用 npm cache clean

poj 1904 King's Quest
Kings Quest 题意:有N个王子和N个妹子;(1 < N < 2000)第i个王子喜欢Ki个妹子;(详见sample)题给一个完美匹配,即每一个王子和喜欢的一个妹子结婚;问每一个王子可以有几种选择(在自己喜欢的妹子里面选),并输出可选…

数据预处理--噪声_为什么数据对您的业务很重要-以及如何处理数据
数据预处理--噪声YES! Data is extremely important for your business.是! 数据对您的业务极为重要。 A human body has five sensory organs, and each one transmits and receives information from every interaction every second. Today, scientists can det…

C++ template
(转自http://www.cnblogs.com/gw811/archive/2012/10/25/2738929.html) C模板 模板是C支持参数化多态的工具,使用模板可以使用户为类或者函数声明一种一般模式,使得类中的某些数据成员或者成员函数的参数、返回值取得任意类型。 模…

js根据经纬度取随机附近经纬度
实现功能: 小程序根据当前经纬度得出随机的附近经纬度显示在地图上做标记点,效果图 实现代码 // map.js var app getApp() var mymap ; var lat ; var long ; var that;function latlog(lat, lon, d 1,d23) {var angle Math.random(1, 360);var …

讽刺笑话_完全不讽刺的2019年网络设计指南
讽刺笑话I’ve written about how to design for the modern web before, way back in 2018. But the web moves forward quickly so those guidelines are already obsolete and outdated, as more modern conventions have become mainstream.早在2018年,我就已经…

模拟城市2.0
题目背景 博弈正在机房颓一个叫做《模拟城市2.0》的游戏。 2048年,经过不懈努力,博弈终于被组织委以重任,成为D市市委书记!他勤学好问,励精图治,很快把D市建设成富强民主文明和谐的美好城市。为了进一步深化…

bzoj:1221;vijos 1552 软件开发
Description 某软件公司正在规划一项n天的软件开发计划,根据开发计划第i天需要ni个软件开发人员,为了提高软件开发人员的效率,公司给软件人员提供了很多的服务,其中一项服务就是要为每个开发人员每天提供一块消毒毛巾,…

u-charts 曲线图中间有部分没数据,导致点和点无法连成线的问题解决
解决曲线图或者折线图在两端中间没有数据时无法绘画成线的问题源码修改, 解决方案: 在数据之间填充假数据,并且创建一个和点的数据同级的 list 来验证是不是假数据,如果是假数据就不绘制点,是真数据才绘制点,达到点和点之间没数据但是能连线的效果 先看效果图: 数据格…

python构建json_如何使用Python构建JSON API
python构建jsonThe JSON API specification is a powerful way for enabling communication between client and server. It specifies the structure of the requests and responses sent between the two, using the JSON format.JSON API规范是启用客户端和服务器之间通信的…

样式集 - 自适应居中弹窗
效果图: 弹窗1代码 <!-- 答题正确弹窗 --><block v-if"answer_true_show"><view class"answer_true_bg"></view><view class"answer_true"><img class"true_bg_img" :src"qualifyi…

struts2中 ServletActionContext与ActionContext区别
1. ActionContext 在Struts2开发中,除了将请求参数自动设置到Action的字段中,我们往往也需要在Action里直接获取请求(Request)或会话(Session)的一些信息,甚至需要直接对JavaServlet Http的请求(HttpServletRequest),响应(HttpServletResponse)操作. 我们需要在Action中取得req…

[记录]calculate age based on date of birth
calculate age based on date of birth know one new webiste:eval.in run php code转载于:https://www.cnblogs.com/fsong/p/5190273.html

有抱负的Web开发人员应考虑的6件事
Becoming a web developer can be as challenging as working out every day.成为网络开发人员就像每天锻炼一样具有挑战性。 It’s important to know what it will take to succeed as a web developer.重要的是要知道要成为一名Web开发人员要取得成功。 Here are 6 things…